import { GAlertWin } from "../../../../../com/mui/controls/GAlertWin";
import { ParamsConst } from "../../../../common/global/ParamsConst";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { KeyBoardManager } from "../../../../../com/gengine/keyBoard/KeyBoardManager";
import { KeyEvent } from "../../../../../com/gengine/keyBoard/KeyEvent";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { ObjCreate } from "../ObjCreate";
import { ValidatorUitl } from "../../../../../com/fyGame/utils/ValidatorUitl";
import { GameRMI } from "../../../net/rmi/GameRMI";
import { AMI_IPlayer_commitIssm } from "../../../../../Message/Game/AMI_IPlayer_commitIssm";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Exception } from "../../../../../Framework/Util/Exception";
import { ErrorCode } from "../../../../common/error/ErrorCode";
import { KeyCode } from "../../../../../com/gengine/keyBoard/KeyCode";
type int = number;
//class IssmAlertWin
    
    export  class IssmAlertWin extends GAlertWin
    {
        constructor(arg1: number, arg2: number)
        {
            this.gameName = ParamsConst.instance.gameName;
            this.messageString1 = "<span><textformat leading=\'10\'><font color=\'#ffffff\' size=\'12\'><b>       网络游戏防沉迷系统及用户隐私说明按照版署《网络游戏未成年》要求：</b></font>\r" + "<font color=\'#ffffff\'>     为预防青少年过度游戏，未满18岁的用户和身份信息不完整的用户将受到防沉迷系统的限制，《" + this.gameName + "》积极响应国家新闻出版总署防沉迷政策要求，开发出网页游戏防沉迷系统。</font>\r" + "<font color=\'#ffffff\'>年龄已满18周岁的玩家，在填写身份资料后，可以不受防沉迷系统影响，自由进行游戏，</font>" + "<font color=\'#FF0033\'>根据身份信息未成年3小时后将被强制下线并且必须下线休息5小时。</font>\r" + "<font color=\'#ffffff\'>     说明：系统只支持输入15位或18位的中国身份证号码，持有其他证件（如：外国护照，军人证，等）者，请与客服GM联系处理。填写身份信息将使我们可以对您的年龄作出判断，以确定您的游戏时间是否需要按照国家新闻出版部署的要求纳入防沉迷系统的管理。</font>\r" + "<font color=\'#ff0033\'>     隐私说明：</font>" + "<font color=\'#ffffff\'>用户填写的身份信息属于用户的隐私。《" + this.gameName + "》游戏绝对尊重用户个人的隐私权。所以，《" + this.gameName + "》游戏绝对不会公开，编辑或透露用户的信息内容，除非有法律许可及公安管理规定。</font></textformat><span/>";
            this.reg = new RegExp("^d{15}|d{18}$");
            this.myPattern2 = new RegExp("^[一-龥]{1,}");
            super(arg1, arg2);
            return;
        }

        protected /* override */ childrenCreated(): void
        {
            var loc3=null;
            var loc5=null;
            if (typeof Alert.title === "string") 
            {
                (title as Object /* flash.text.TextField */).htmlText = Alert.title;
            }
            message.autoSize = flash.text.TextFieldAutoSize.LEFT;
            var loc1=new GTextFormat(FontUtil.songtiName, "12", null, null, null, null, null, null, null, null, null, null, 5);
            loc1.align = flash.text.TextFormatAlign.LEFT;
            message.x = 20;
            message.y = 45;
            message.width = 520;
            message.wordWrap = true;
            message.selectable = false;
            message.defaultTextFormat = loc1;
            message.htmlText = this.messageString1;
            boarder.width = 260;
            boarder.height = 150;
            prompt = new BaseWindow();
            (prompt as BaseWindow).titleHeight = 26;
            prompt.width = 575;
            var loc2=(prompt as BaseWindow).closeBtn;
            if (loc2) 
            {
                loc2.visible = false;
            }
            prompt.height = 398;
            (prompt as BaseWindow).title = "防沉迷";
            loc3 = ResouceConst.getScaleBitmap("WindowCenterB");
            loc3.width = 542;
            loc3.height = 349;
            loc3.x = 17;
            loc3.y = 37;
            addChild(background);
            prompt.addChild(title);
            prompt.addChild(loc3);
            prompt.addChild(message);
            prompt.addEventListener(WindowEvent.CLOSE, this.Close_Handler, false, 0, true);
            addChild(prompt);
            var loc4;
            (loc4 = new GButton()).label = "提交";
            loc4.name = "HandInButton";
            loc4.styleName = "Button";
            loc4.width = 60;
            loc4.height = 28;
            loc4.x = 200;
            loc4.y = 350;
            loc4.addEventListener(flash.events.MouseEvent.CLICK, this.handInHandler);
            KeyBoardManager.instance.addEventListener(KeyEvent.KEY_DOWN, this.onKeyDownHandle);
            this.nameLabel = new GLabel();
            this.nameLabel.text = "真实姓名：";
            this.nameLabel.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, 16777215));
            this.nameLabel.x = 102;
            this.nameLabel.y = 293;
            prompt.addChild(this.nameLabel);
            this.userName = new GTextInput();
            this.userName.styleName = "GTextInput";
            this.userName.addEventListener(flash.events.Event.CHANGE, this.onTextNameInputHandler);
            this.userName.name = "Name";
            this.userName.restrict = "[一-龥]";
            this.userName.x = 173;
            this.userName.y = 290;
            this.userName.width = 160;
            this.userName.height = 22;
            this.userName.setStyle("textPadding", 3);
            prompt.addChild(this.userName);
            (loc5 = ObjCreate.createGTextField("如：王五", 348, 293, 200, 20, prompt)).selectable = true;
            this.IDNumLabel = new GLabel();
            this.IDNumLabel.text = "身份证号码：";
            this.IDNumLabel.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, 16777215));
            this.IDNumLabel.x = 90;
            this.IDNumLabel.y = 323;
            prompt.addChild(this.IDNumLabel);
            this.userIDNum = new GTextInput();
            this.userIDNum.styleName = "GTextInput";
            this.userIDNum.restrict = "[0-9Xx]";
            this.userIDNum.addEventListener(flash.events.Event.CHANGE, this.onTextIDInputHandler);
            this.userIDNum.name = "NameID";
            this.userIDNum.x = 173;
            this.userIDNum.y = 320;
            this.userIDNum.width = 160;
            this.userIDNum.height = 22;
            this.userIDNum.setStyle("textPadding", 3);
            prompt.addChild(this.userIDNum);
            (loc5 = ObjCreate.createGTextField("如：440106198101010155", 348, 323, 200, 20, prompt)).selectable = true;
            var loc6;
            (loc6 = new GButton()).label = "取消";
            loc6.name = "CancelButton";
            loc6.styleName = "Button";
            loc6.width = 60;
            loc6.height = 28;
            loc6.x = 300;
            loc6.y = 350;
            loc6.addEventListener(flash.events.MouseEvent.CLICK, this.Close_Handler);
            prompt.addChild(loc4);
            prompt.addChild(loc6);
            prompt.x = (stageWidth - prompt.width) / 2;
            prompt.y = (stageHeight - prompt.height) / 2;
            this.warningTxtLabel = new GLabel();
            this.warningTxtLabel.text = "";
            this.warningTxtLabel.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, 16711731));
            this.warningTxtLabel.x = 370;
            this.warningTxtLabel.y = 355;
            this.warningTxtLabel.width = 220;
            prompt.addChild(this.warningTxtLabel);
            return;
        }

        /* internal  */onTextNameInputHandler(arg1: Object /* flash.events.Event */): void
        {
            this.validatorNameInput();
            return;
        }

        /* internal  */onTextIDInputHandler(arg1: Object /* flash.events.Event */): void
        {
            this.validatorIdInput();
            return;
        }

        /* internal  */validatorNameInput(): Boolean
        {
            var loc1=false;
            if (this.userName.text != "") 
            {
                if (this.userName.text.length < 2 || this.userName.text.length > 6 || !ValidatorUitl.isChinese(this.userName.text)) 
                {
                    this.warningTxtLabel.text = " 姓名必须是2-6个汉字";
                }
                else 
                {
                    this.warningTxtLabel.text = "";
                    loc1 = true;
                }
            }
            else 
            {
                this.warningTxtLabel.text = "姓名不能为空";
            }
            return loc1;
        }

        /* internal  */validatorIdInput(): Boolean
        {
            var loc1=false;
            if (ValidatorUitl.isCNID(this.userIDNum.text)) 
            {
                this.warningTxtLabel.text = "";
                loc1 = true;
            }
            else 
            {
                this.warningTxtLabel.text = "身份证号码输入不正确！";
            }
            return loc1;
        }

        /* internal  */handInHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this.validatorNameInput() && this.validatorIdInput()) 
            {
                removeDragHandleer();
                GameRMI.instance.iPlayerPrxHelper.commitIssm_async(new AMI_IPlayer_commitIssm(this.successHandler, this.errorHandler), this.userName.text, this.userIDNum.text);
            }
            return;
        }

        /* internal  */successHandler(arg1: Object, arg2: int): void
        {
            if (this.parent) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.IssmVerified));
                this.parent.removeChild(this);
            }
            return;
        }

        /* internal  */errorHandler(arg1: Exception): void
        {
            this.warningTxtLabel.text = ErrorCode.getErrorStringByCode(arg1.code);
            return;
        }

        /* internal  */Close_Handler(arg1: Object /* flash.events.Event */): void
        {
            removeDragHandleer();
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            return;
        }

        /* internal  */onKeyDownHandle(arg1: KeyEvent): void
        {
            if (arg1.keyEvent.keyCode == KeyCode.ENTER) 
            {
                if (this.validatorNameInput() && this.validatorIdInput()) 
                {
                    removeDragHandleer();
                    GameRMI.instance.iPlayerPrxHelper.commitIssm_async(new AMI_IPlayer_commitIssm(this.successHandler, this.errorHandler), this.userName.text, this.userIDNum.text);
                }
            }
            return;
        }

        /* internal */ /* var */userName: GTextInput;

        /* internal */ /* var */userIDNum: GTextInput;

        /* internal */ /* var */nameLabel: GLabel;

        /* internal */ /* var */IDNumLabel: GLabel;

        /* internal */ /* var */warningTxtLabel: GLabel;

        /* internal */ /* var */gameName: string;

        /* internal */ /* var */messageString1: string;

        /* internal */ /* var */reg: RegExp;

        /* internal */ /* var */myPattern2: RegExp;
    }
